﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyMvcStoreApplication.Models;
using MyMvcStoreApplication.Repositories;

namespace MyMvcStoreApplication.Controllers
{ 
    public class ArtistaController : Controller
    {
        private ArtistaRepository repository = new ArtistaRepository();

        //
        // GET: /Artista/

        public ViewResult Index()
        {
            return View(repository.GetAll());
        }

        //
        // GET: /Artista/Details/5

        public ViewResult Details(int id)
        {
            return View(repository.Get(id));
        }

        //
        // GET: /Artista/Create

        public ActionResult Create()
        {
            return View(new Artista());
        } 

        //
        // POST: /Artista/Create

        [HttpPost]
        public ActionResult Create(Artista artista)
        {
            if (ModelState.IsValid)
            {
                repository.SaveNew(artista);
                return RedirectToAction("Index");  
            }

            return View(artista);
        }
        
        //
        // GET: /Artista/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(repository.Get(id));
        }

        //
        // POST: /Artista/Edit/5

        [HttpPost]
        public ActionResult Edit(Artista artista)
        {
            if (ModelState.IsValid)
            {
                repository.SaveModify(artista);
                return RedirectToAction("Index");
            }
            return View(artista);
        }

        //
        // GET: /Artista/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(repository.Get(id));
        }

        //
        // POST: /Artista/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            repository.Delete(id);
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            repository.Dispose();
            base.Dispose(disposing);
        }
    }
}